<template>
  <Popup
      :round="round"
      v-model="visible"
      :overlay="true"
      :close-on-click-overlay="false"
      :safe-area-inset-bottom="true"
      :transition-appear="true"
      :close-on-popstate="true"
      overlay-class="layer_wrap"
      @click-overlay="handleClose"
  >
    <div class="report-result">
      <!--1:成功-2:失败-3:警告-->
      <template v-if="true">
        <div class="icon-result" :class="getClassName"/>
        <div class="title">{{ info.title }}</div>
        <div class="content">{{ info.content }}</div>
      </template>
      <div class="button" @click="handleClose(false)">
        确定&nbsp;({{ `${time / 1000}` }})
      </div>
    </div>
  </Popup>
</template>

<script>
import {Popup} from 'vant';

export default {
  name: 'ReportResult2',

  componentName: "ReportResult2",

  props: {
    visible: {
      type: Boolean,
      required: false
    },
    info: {
      type: Object,
      required: true
    },
  },

  components: {
    Popup,
  },

  data() {
    return {
      round: true,
      time: 60000,
      timer: null,
    }
  },

  computed: {
    getClassName(){
      let {state} = (this.info);
      switch (state) {
        case 0:
          return 'icon-fail';
        case 1:
          return 'icon-success';
        case 2:
          return true;
      }
    }
  },

  mounted() {
    console.log('init')
  },

  methods: {
    handleClose() {
      this.$emit('handleCancel')
      this.$emit('handle-cancel')
      clearInterval(self.timer);
    }
  },

  watch: {
    visible: {
      handler: function (val) {
        const self = this;
        if (val) {
          self.time = (self.info.time) * 1000;
          self.timer = setInterval(() => {
            self.time = (self.time - 1000);
            if ((self.time) === 0) {
              self.handleClose();
              clearInterval(self.timer)
            }
            console.log('1关闭倒计时')
          }, 1000)
        } else {
          clearInterval(self.timer)
          console.log('2关闭倒计时')
        }
      },
      deep: true,
      immediate: true
    }
  },

}
</script>

<style lang="scss" scoped>
@import "./assets/style";
</style>
